<?php
/**
* authModel
*/
class authModel
{
	private $auth = "";
	public function __construct()
	{
		if (isset($_SESSION['auth']) && (!empty($_SESSION['auth']))) {
			$this->auth = $_SESSION['auth'];
		}
	}
	public function loginsubmit()
	{
		if (empty($_POST['username']) || empty($_POST['password'])) {
			return  false;
		}
		$username = daddslashes($_POST['username']);
		$password = daddslashes($_POST['password']);
		if ($this->auth = $this->checkauth($username, $password)) {
			$_SESSION['auth'] = $this->auth;
			return true;
		} else {
			return false;
		}
	}
	private function checkauth($username, $password)
	{
		$adminobj = M('admin');
		$res = $adminobj->findOne_by_username($username);
		if ((!empty($res)) && $res['password'] == $password) {
			return $res;
		} else {
			return false;
		}
	}
	public function logout()
	{
		unset($_SESSION['auth']);
		$this->auth = '';
	}
	public function getauth()
	{
		return $this->auth;
	}
}